﻿<?

$connect = mysql_connect('localhost', 'tass', '114'); // DB 연결
$db_id=mysql_select_db("tass",$connect);  // DB 선택

$word   = $_REQUEST['word'];
$meaning = $_REQUEST['meaning'];
if($word!=''){
    $sql  = "INSERT INTO admin_word VALUES ('$word','$meaning')"; //검색된 단어가 없으면 저장
    mysql_query($sql, $connect);
}

$sql = "SELECT COUNT(word) AS num, word FROM admin_word GROUP BY word;";

$rs = mysql_query($sql, $connect);
while($result = mysql_fetch_array($rs)){
  $num = $result[num];
  $word = $result[word];
      $sql = "SELECT * FROM admin_word WHERE word = '$word';";
      $rss = mysql_query($sql, $connect);

      $xmlList.="<word name=\"$word\">";

      while($result_1 = mysql_fetch_array($rss)){
 //       $word_1 = $result_1[word];
          $meaning_1 = $result_1[meaning];
        
          $xmlList.="<meaning>$meaning_1</meaning>";
      }
      $xmlList.="</word>";
}
mysql_free_result($rs);

$xmlList="<?xml version='1.0' encoding='utf-8'?><admin>$xmlList</admin>";
/*
$fp = fopen("admin_insert.xml","w");
fputs($fp, $xmlList);
fclose($fp);
*/
 echo    $xmlList;

?>